package org.ellwood.core.common.result;

import io.swagger.v3.oas.annotations.media.Schema;
import org.ellwood.core.common.entity.socket.SocketBean;
import org.ellwood.core.common.enums.SocketChannelEnum;

/**
 * @ProjectName: ellwood-boot-pro
 * @PackageName: org.ellwood.core.common.entity
 * @ClassName: SocketResult
 * @Description: // socket 返回结果
 * @Author: Ellwood
 * @CreateDate: 2024/6/14 - 下午4:31
 * @Version: V1.0.0
 */
public class SocketResult<T> extends SocketBean<T> {

    @Schema(description = "状态码。200代表成功，其他代表失败")
    private int status;

    {
        status=200;
    }

    public static <T> SocketResult<T> success() {
        SocketResult socketResult = new SocketResult();
        socketResult.data = (T) "";
        return socketResult;
    }

    public static <T> SocketResult<T> success(SocketChannelEnum channel, T data) {
        SocketResult socketResult = new SocketResult();
        socketResult.channel = channel;
        socketResult.data = (data != null) ? data : (T) "";
        return socketResult;
    }

    public static <T> SocketResult<T> success(SocketChannelEnum channel, T data, String message) {
        SocketResult<T> socketResult = new SocketResult<>();
        socketResult.channel = channel;
        socketResult.data = (data != null) ? data : (T) "";
        return socketResult;
    }

    public static <T> SocketResult<T> fail(SocketChannelEnum channel, T data) {
        SocketResult socketResult = new SocketResult();
        socketResult.status = 0;
        socketResult.channel = channel;
        socketResult.data = (data != null) ? data : (T) "";
        return socketResult;
    }

}
